/*
 * Copyright (c) 2006, 2022, webrx.cn All rights reserved.
 *
 */
package cn;

import com.auth0.jwt.JWT;
import com.auth0.jwt.JWTVerifier;
import com.auth0.jwt.algorithms.Algorithm;
import com.auth0.jwt.interfaces.DecodedJWT;

import java.util.Calendar;

/**
 * <p>Project: smvc2022 - Demo
 * <p>Powered by webrx On 2022-03-31 11:21:43
 * <p>Created by IntelliJ IDEA
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 17
 */
public class Demo {
    public static void main(String[] args) {
        String secret = "webrx";
        Calendar c = Calendar.getInstance();
        c.add(Calendar.SECOND,5);
        String token = JWT.create().withExpiresAt(c.getTime()).sign(Algorithm.HMAC256(secret));
        System.out.println(token);
        //eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE2NDg2OTg5OTR9.V1ARuEJ3zHJ9jn48nvMZR_SpIX0_UTsx2KBfCSjE2bI

        JWTVerifier jwtVerifier = JWT.require(Algorithm.HMAC256(secret)).build();
        //验证JWT
        DecodedJWT decodedJWT = jwtVerifier.verify("eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE2NDg2OTc2MTd9.idSxrSq5ioMFGquYuEvYcvHqFvZr201uG2v_dUfmooA");


    }
}
